package app.android.com.wuandroidapp.playair;

import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;

import app.android.com.wuandroidapp.R;

public class MainActivity extends Activity {
	Handler hand;
	SoundPool sp;
	int ex;
	int sh;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		final Myview m = new Myview(this);
		setContentView(m);
		
		
		sp = new SoundPool(9, AudioManager.STREAM_MUSIC, 0);
		ex = sp.load(this, R.raw.explose, 1);
		//sh = sp.load(this, R.raw.shot, 1);

		
		
		hand = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case 10:
					
					m.invalidate();
					if(m.arr.size()<3){
					
                    m.createRobotAir();
					}
					//hand.sendEmptyMessageDelayed(10, 2000);
				hand.sendEmptyMessageDelayed(10, 50);
				
				if(t){
					sp.play(ex, 1, 1, 0, 0, 1);
				}	
					break;
				}
			}

		};
	}

	
boolean t=true;
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
	
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		
	t=false;
		hand.sendEmptyMessage(10);
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
	
		hand.sendEmptyMessage(10);
	
		super.onResume();
	}
}
